package com.panda.ServletDemo.controller.test;

import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.panda.ServletDemo.controller.BaseHttpServlet;
import com.panda.ServletDemo.entity.User;
import com.panda.ServletDemo.utils.ResultResponse;
import com.panda.ServletDemo.utils.ResultResponseUtil;


@WebServlet(value="/testServlet",loadOnStartup = 1) 
@MultipartConfig
public class testServlet extends BaseHttpServlet {

	private static final long serialVersionUID = -3002863118777534059L;
	
	private static final Logger logger = LoggerFactory.getLogger(testServlet.class);
	
	public String testGetMethod(HttpServletRequest request,HttpServletResponse response){
		logger.info("开始调用testServlet.testGetMethod()...");
		request.setAttribute("h", "haha");
		return "/test/a";
	}
	
	
	public ResultResponse testJsonMethod(HttpServletRequest request,HttpServletResponse response){
		logger.info("开始调用testServlet.testGetMethod()...");
		return ResultResponseUtil.success("成功了！",new User("panda", 20, "180"));
	}
	
	public ResultResponse testAJaxMethod1(HttpServletRequest request,HttpServletResponse response){
		logger.info("开始调用testServlet.testAJaxMethod()...");
		logger.info("content-type:{}",request.getContentType()); 
		User user = null;
		try{
			user = JSON.parseObject(request.getParameter("jsonData"), User.class);
		}catch (Exception e){
			logger.error("fastJson转vo失败！:{}",e);
		}
		return ResultResponseUtil.success("success", user);
	}
	
	public ResultResponse testInitMethod(HttpServletRequest request,HttpServletResponse response) {
		logger.info("开始调用testServlet.testInitMethod()...");
		return ResultResponseUtil.success("ok");
	}
	
	public String test(HttpServletRequest request,HttpServletResponse response) {
		logger.info("开始调用testServlet.testInitMethod()...");
		return "/test/index";
	}
}
